<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="../include/admincontent.jsp" %>


<div id="location">当前位置：招聘方案管理 > 岗位模板管理</div>
<!-- 筛选条件 -->
<div id="sy_search" class=" f0f0f0" style="display: inline-block">
    <%--<form id="advanceQueryParam">--%>
    <form id="conditionform">
        <div style="background-color: #f0f0f0">
            <div class="clearfix more_query_area label150">
                <div class="query_area_body clearfix">
                    <div class="record_item">
                        <div class="record_item">
                            <div class="label">模板名称:</div>
                            <div class="content">
                                <div><input type="text" name="tempname"/></div>
                            </div>
                        </div>
                    </div>
                    <div class="record_item">
                        <div class="record_item">
                            <div class="label">岗位名称:</div>
                            <div class="content">
                                <div><input type="text" name="jobname"/></div>
                            </div>
                        </div>
                    </div>
                    <div class="record_item">
                        <div class="record_item">
                            <div class="label">招聘人数:</div>
                            <div class="content">
                                <div><input type="text" name="zpcount"/></div>
                            </div>
                        </div>
                    </div>
                    <div class="record_item">
                        <div class="record_item">
                            <div class="label">模板类型:</div>
                            <div class="content">
                                <div><select name="type">
                                    <option value="">不限</option>--%>
                                    <option value="A">社会招聘</option>
                                    <option value="B">校园招聘</option>
                                    <option value="C">中专招聘</option>
                                   <%-- <option value="D">内部</option>--%>
                                </select></div>
                            </div>
                        </div>
                    </div>
                    <div class="record_item">
                        <div class="record_item">
                            <div class="label">工作职责:</div>
                            <div class="content">
                                <div><input type="text" name="workcont"/></div>
                            </div>
                        </div>
                    </div>
                    <div class="record_item">
                        <div class="record_item">
                            <div class="label">技能要求:</div>
                            <div class="content">
                                <div><input type="text" name="workreq"/></div>
                            </div>
                        </div>
                    </div>
                    <div class="record_item">
                        <div class="record_item">
                            <div class="label">模板状态:</div>
                            <div class="content">
                                <div><select name="state">
                                    <option value="">不限</option>
                                    <option value="启用">启用</option>
                                    <option value="停用">停用</option>
                                </select></div>
                            </div>
                        </div>
                    </div>
                    <div class="record_item">
                        <div class="toolbars">
                            <a id="searchbtn" >
                                <em class="ico16 search_16"></em>
                                <span class="menu_span" title="查询">查询</span>
                            </a>
                            <a id="searchreset">
                                <em class="ico16 refresh_16"></em>
                                <span class="menu_span" title="重置">重置</span>
                            </a>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </form>
</div>
<div id="Content" class="bg-content">
    <div class="toolbars">
        <a id="btn_add">
            <em class="ico16 add_new"></em>
            <span class="menu_span">新建模板</span>
        </a>
        <a id="btn_delete">
            <em class="ico16 del_16"></em>
            <span class="menu_span">删除模板</span>
        </a>
        <a id="btn_edit">
            <em class="ico16 editor_16"></em>
            <span class="menu_span">编辑模板</span>
        </a>
        <a id="btn_stop">
            <em class="ico16 enabled_16"></em>
            <span class="menu_span">启用/禁用</span>
        </a>
    </div>
</div>
<div style="overflow:hidden;">
    <div id="div_table" style="bottom: 0px">
        <table class="layui-hide" id="table" lay-filter="jobtemplatesTable"></table>
    </div>
</div>

<div id="exprotForm" style="display: none">
    <form id="excelValid" method="POST" action="" enctype="multipart/form-data">
        <div class="help">
            <b>注意：</b><br>
            1、第一行必须是标题,并且存在以"身份证"开头的列名。<br>
            2、数据导入请上传excel格式(<b>支持：xls和xlsx</b>)文件。
        </div>
        <table class="treeTable searchform">
            <thead>

            <tr>
                <td width="80">Excel文件：</td>
                <td>
                    <div><input type="file" name="excel" datatype="*" nullmsg="请选择Excel文件"/></div>
                </td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <button class="op" id="exprotFormsubmit">导入Excel</button>
                </td>
            </tr>
            </thead>
        </table>
    </form>
</div>
<link rel="stylesheet" href="../resources/js/plugins/layui/css/layui.css"/>
<script src="../resources/js/plugins/layui/layui.all.js" type="text/javascript"></script>
<script type="text/html" id="rowToolBar">
    <a class="layui-btn layui-btn-xs" lay-event="start_stop">启用/禁用</a>
</script>
<script type="text/javascript">
    $(function () {
        $("#btn_add").click(function () {
            openLayer('添加岗位模板', '/ProjectJobTemplate/edit', '98%', '98%');
        });
    })


    $(document).ready(function () {
        layui.use('table', () => {
            let table = layui.table;
            table.render({
                id: 'table'
                , elem: '#table'
                , height: 'full'
                , url: '/ProjectJobTemplate/queryByPageJson?' + $("#conditionform").serialize() //数据接口
                , title: '用户表'
                , page: true //开启分页
                , cols: [[ //表头
                    {type: 'checkbox', fixed: 'left', width: 50}
                    , {type: 'numbers', title: '序号', width: '10%', sort: true}
                    , {field: 'tempname', title: '模板名称', width: '10%', sort: true}
                    , {field: 'jobname', title: '岗位名称', width: '10%', sort: true}
                    , {field: 'zpcount', title: '招聘人数', width: '10%', sort: true}
                    , {field: 'typeS', title: '模板类型', width: '10%', sort: true}
                    , {field: 'state', title: '模板状态', width: '10%', sort: true}
                    , {field: 'workcont', title: '工作职责', width: '20%', sort: true}
                    , {field: 'workreq', title: '技能要求', width: '20%', sort: true}
                    /*, { title: '操作', fixed: 'right', width: '10%', toolbar: '#rowToolBar'}*/
                ]]
            });
            reload = () => {
                table.reload('table');
            }
            document.tablereload = reload;
            $("#searchbtn").on('click', () => {
                table.reload('table', {
                    url: '/ProjectJobTemplate/queryByPageJson?' + $("#conditionform").serialize()
                    , page: {
                        curr: 1
                    }
                })
            })
            table.on('tool(jobtemplatesTable)' ,(obj)=>{
                let event = obj.event;
                let data = obj.data;
                if(event === 'start_stop') {
                    let urL = '/ProjectJobTemplate/' + (data.state === '启用'?'stop':'start');
                    let statE = data.state === '启用'?'停用':'启用'
                    $.ajax({
                        url: urL,
                        data: {id: data.id, state: statE},
                        dataType: 'JSON',
                        type: "POST",
                        success: function (json) {
                            layer.closeAll();
                            if (json.state) {
                                if (json.Message != null) {
                                    layer.alert(json.Message);
                                } else {
                                    layer.alert(json.message);
                                }
                                reload();
                            } else {
                                if (json.Message != null) {
                                    layer.alert(json.Message);
                                } else {
                                    layer.alert(json.message);
                                }
                            }
                        }
                    })
                }
            })
        });



        $("#btn_start").click(function () {
            let chosendata = layui.table.checkStatus('table').data;
            if (chosendata.length < 1) {
                layer.msg('至少选择一条信息');
            } else {
                layer.confirm('是否启用该模板？', {
                    btn: ['是', '否']
                }, function () {
                    var ids = "";
                    chosendata.forEach(function (item) {
                        ids += item.id + ",";
                    });
                    ids = ids.substring(0, ids.length - 1);
                    $.ajax({
                        url: '/ProjectJobTemplate/start',
                        data: {id: ids, state: "启用"},
                        dataType: 'JSON',
                        type: "POST",
                        success: function (json) {
                            layer.closeAll();
                            if (json.state) {
                                if (json.Message != null) {
                                    layer.alert(json.Message);
                                } else {
                                    layer.alert(json.message);
                                }
                                reload();
                            } else {
                                if (json.Message != null) {
                                    layer.alert(json.Message);
                                } else {
                                    layer.alert(json.message);
                                }
                            }
                        }
                    })
                }, function () {
                    layer.closeAll();
                });
            }

        });

        $("#btn_stop").click(function () {
            let chosendata = layui.table.checkStatus('table').data;
            if (chosendata.length < 1) {
                layer.msg('至少选择一条信息');
            } else {
                layer.confirm('是否停用该模板？', {
                    btn: ['是', '否']
                }, function () {
                    var ids = "";
                    chosendata.forEach(function (item) {
                        ids += item.id + ",";
                    });
                    ids = ids.substring(0, ids.length - 1);
                    $.ajax({
                        url: '/ProjectJobTemplate/stop',
                        data: {id: ids, state: "停用"},
                        dataType: 'JSON',
                        type: "POST",
                        success: function (json) {
                            layer.closeAll();
                            if (json.state) {
                                if (json.Message != null) {
                                    layer.alert(json.Message);
                                } else {
                                    layer.alert(json.message);
                                }
                                reload();
                            } else {
                                if (json.Message != null) {
                                    layer.alert(json.Message);
                                } else {
                                    layer.alert(json.message);
                                }
                            }
                        }
                    })
                }, function () {
                    layer.closeAll();
                });
            }
        });
        $("#btn_delete").click(function () {
            deleteTemp();
        });
        $("#btn_edit").click(function () {
            let chosendata = layui.table.checkStatus('table').data;
            if (chosendata.length < 1) {
                layer.msg('至少选择一条信息');
            } else if (chosendata.length > 1) {
                layer.msg('选择一条信息');
            } else {
                var ids = chosendata[0].id;
                openLayer('编辑岗位模板', '/ProjectJobTemplate/edit?id=' + ids, '98%', '98%');
            }
        });

        function deleteTemp() {
            let chosendata = layui.table.checkStatus('table').data;
            if (chosendata.length < 1) {
                layer.msg('至少选择一条信息');
            } else {
                layer.confirm('删除后无法进行回复,请谨慎操作! <br/>是否删除该模板？', {
                    btn: ['是', '否']
                }, function () {
                    var ids = "";
                    chosendata.forEach(function (item) {
                        ids += item.id + ",";
                    });
                    ids = ids.substring(0, ids.length - 1);
                    $.ajax({
                        url: '/ProjectJobTemplate/delete',
                        data: {id: ids},
                        dataType: 'JSON',
                        type: "POST",
                        success: function (json) {
                            layer.closeAll();
                            if (json.state) {
                                if (json.Message != null) {
                                    layer.alert(json.Message);
                                } else {
                                    layer.alert(json.message);
                                }
                                reload();
                            } else {
                                if (json.Message != null) {
                                    layer.alert(json.Message);
                                } else {
                                    layer.alert(json.message);
                                }
                            }
                        }
                    })

                }, function () {
                    layer.closeAll();
                });
            }
        }

    });


    function enableTemp(id) {
        layer.confirm('是否启用该模板？', {
            btn: ['是', '否']
        }, function () {
            $.ajax({
                url: '/ProjectJobTemplate/start',
                data: {id: id, state: "启用"},
                dataType: 'JSON',
                type: "POST",
                success: function (json) {
                    layer.closeAll();
                    if (json.state) {
                        if (json.Message != null) {
                            layer.alert(json.Message);
                        } else {
                            layer.alert(json.message);
                        }
                        getList();
                    } else {
                        if (json.Message != null) {
                            layer.alert(json.Message);
                        } else {
                            layer.alert(json.message);
                        }
                    }
                }
            })

        }, function () {
            layer.closeAll();
        });
    }

    function stopTemp(id) {
        layer.confirm('是否停用该模板？', {
            btn: ['是', '否']
        }, function () {
            $.ajax({
                url: '/ProjectJobTemplate/stop',
                data: {id: id, state: "停用"},
                dataType: 'JSON',
                type: "POST",
                success: function (json) {
                    layer.closeAll();
                    if (json.state) {
                        if (json.Message != null) {
                            layer.alert(json.Message);
                        } else {
                            layer.alert(json.message);
                        }
                        getList();
                    } else {
                        if (json.Message != null) {
                            layer.alert(json.Message);
                        } else {
                            layer.alert(json.message);
                        }
                    }
                }
            })
        }, function () {
            layer.closeAll();
        });
    }

    //模板列表信息
    function getList() {
        $("#page").myPagination({
            cssStyle: "pagination",
            singleCheck: true,
            saveChecked: true,
            ajax: {
                on: true,
                url: '/ProjectJobTemplate/queryByPage',
                param: $("#conditionform").serialize(),
                dataType: 'html',
                callback: function (data) {
                    $("#result").html(data);
                }
            }
        });
    }

</script>
</body>
</html>